package com.alter.flowable.config;

import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.ui.common.properties.FlowableCommonAppProperties;
import org.flowable.ui.modeler.properties.FlowableModelerAppProperties;
import org.flowable.ui.modeler.service.AppDefinitionPublishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import javax.sql.DataSource;

/**
 * @ClassName ProcessConfig
 * @Description 配置类
 * @Author xiong
 * @Date 2020/6/22 9:45
 */
@Configuration
public class ProcessConfig {
    @Autowired
    private DataSource datasource;

    @Autowired
    private DataSourceTransactionManager dataSourceTransactionManager;

    @Bean
    public SpringProcessEngineConfiguration springProcessEngineConfiguration(){
        SpringProcessEngineConfiguration springProcessEngineConfiguration = new SpringProcessEngineConfiguration();
        // 设置数据眼
        springProcessEngineConfiguration.setDataSource(datasource);
        // 自动创建表
        springProcessEngineConfiguration.setDatabaseSchemaUpdate(SpringProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        // 事务管理器
        springProcessEngineConfiguration.setTransactionManager(dataSourceTransactionManager(datasource));
        return springProcessEngineConfiguration;
    }

    /**
     * @Description //配置事务管理器
     * @Date 2020/6/22 10:29
     **/
    @Bean
    public DataSourceTransactionManager dataSourceTransactionManager(DataSource datasource){
        return new DataSourceTransactionManager(datasource);
    }
//    @Bean
//    public FlowableCommonAppProperties flowableCommonAppProperties(){
//        return new FlowableCommonAppProperties();
//    }
//    @Bean
//    public FlowableModelerAppProperties flowableModelerAppProperties(){
//        FlowableModelerAppProperties flowableModelerAppProperties = new FlowableModelerAppProperties();
////        flowableModelerAppProperties.setDataSourcePrefix();
//        flowableModelerAppProperties.setDeploymentApiUrl("http://localhost:8080/flowable-task/app-api");
//        flowableModelerAppProperties.setRestEnabled(true);
//        return flowableModelerAppProperties;
//    }
//    @Bean
//    public AppDefinitionPublishService appDefinitionPublishService(){
//        return new AppDefinitionPublishService(flowableCommonAppProperties(), flowableModelerAppProperties());
//    }


}
